<?php

namespace app\common\utils;

/**
 * 全局初始化设置
 */
class Init
{
    public static $log_suffix = 'api'; //日志文件后缀
    public static $request_id; //一次请求周期的唯一id，用于日志追踪
    public static $log_sort = 1; //全局log顺序
    public static $request_start_time; //一次请求开始的毫秒时间戳
    public static $post_data = []; //客户端传递的参数全局使用
    public static $sql = []; //一次请求的所有SQL语句

    public static function setLogSuffix($suffix = 'api')
    {
        self::$log_suffix = $suffix;
    }

    /**
     * 设置或释放全局唯一请求ID
     * @param $action string set/unset
     * @return void
     */
    public static function setRequestId($action = 'set')
    {
        if ($action == 'set') {
            self::$request_id = MyTools::getRandomStr();
        } else {
            self::$request_id = null;
        }
        self::$log_sort = 1;
    }

    /**
     * 设置或释放全局请求的开始时间
     * @param $action string set/unset
     * @return void
     */
    public static function setRequestStartTime($action = 'set')
    {
        if ($action == 'set') {
            self::$request_start_time = microtime(true) * 1000;
        } else {
            self::$request_start_time = null;
        }
    }

}